import request from '@/utils/request'

// 左侧菜单管理API
export function getSideMenuList(params) {
  return request({
    url: '/ios/side-menu/list',
    method: 'get',
    params
  })
}

export function createSideMenu(data) {
  return request({
    url: '/ios/side-menu',
    method: 'post',
    data
  })
}

export function updateSideMenu(id, data) {
  return request({
    url: `/ios/side-menu/${id}`,
    method: 'put',
    data
  })
}

export function deleteSideMenu(id) {
  return request({
    url: `/ios/side-menu/${id}`,
    method: 'delete'
  })
}

export function updateSideMenuOrder(data) {
  return request({
    url: '/ios/side-menu/order',
    method: 'put',
    data
  })
}

// 苹果菜单管理API (统一接口)
export function getAppleMenuList(type = 1) {
  return request({
    url: '/applemenu/list',
    method: 'get',
    params: { type }
  })
}

export function saveAppleMenu(data) {
  return request({
    url: '/applemenu/save',
    method: 'post',
    data
  })
}

export function deleteAppleMenu(data) {
  return request({
    url: '/applemenu/delete',
    method: 'post',
    data
  })
}

// 小球菜单管理API (兼容旧接口)
export function getBallMenuList(params) {
  return getAppleMenuList(2)
}

export function createBallMenu(data) {
  // 新增时不需要id，过滤掉id字段
  const menuData = { ...data }
  delete menuData.id
  return saveAppleMenu({ ...menuData, type: 2 })
}

export function updateBallMenu(id, data) {
  // 修改时需要id
  return saveAppleMenu({ ...data, id, type: 2 })
}

export function deleteBallMenu(id) {
  return deleteAppleMenu(id)
}

export function updateBallMenuOrder(data) {
  return saveAppleMenu({ ...data, type: 2 })
}

// 首页文本管理API
export function getApplePageList() {
  return request({
    url: '/applepage/list',
    method: 'get'
  })
}

export function saveApplePage(data) {
  return request({
    url: '/applepage/save',
    method: 'post',
    data
  })
}

export function deleteApplePage(data) {
  return request({
    url: '/applepage/delete',
    method: 'post',
    data
  })
}

// 通用上传接口
export function uploadIcon(file) {
  const formData = new FormData()
  formData.append('image', file) // 使用 image 作为字段名
  return request({
    url: '/image/ossUpload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
